package com.example.demofx.master;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;

import java.util.Objects;

public class Group {
    private int groupId; // 组的 ID（数据库中的主键）
    private String groupName; // 分组名称
    private final IntegerProperty contactCount = new SimpleIntegerProperty(0);
    private final BooleanProperty deleted = new SimpleBooleanProperty(false);

    public Group() {}

    public Group(int groupId, String groupName) {
        this.groupId = groupId;
        this.groupName = groupName;
    }

    public Group(String groupName) {
        this(-1, groupName); // 默认构造函数，-1 表示未分配 ID
    }

    public int getGroupId() {
        return groupId;
    }

    public void setGroupId(int groupId) {
        this.groupId = groupId;
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public int getContactCount() { return contactCount.get(); }
    public void setContactCount(int count) { contactCount.set(count); }
    public IntegerProperty contactCountProperty() { return contactCount; }

    public boolean isDeleted() { return deleted.get(); }
    public void setDeleted(boolean isDeleted) { deleted.set(isDeleted); }
    public BooleanProperty deletedProperty() { return deleted; }

    // 重写 toString 方法，返回组名
    @Override
    public String toString() {
        return groupName; // 显示组名
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Group group = (Group) o;
        return groupId == group.groupId;
    }

    @Override
    public int hashCode() {
        return Objects.hash(groupId);
    }
}